#include <bits/stdc++.h>
// 2025/01/21
// tag: 
// Author: Zhang Muen
using namespace std;

class UF
{
public:
    vector<int> parents, enemy;
    int cnt;

    UF(int n)
    {
        cnt = n;
        for (int i = 0; i < n; i++)
            parents.push_back(i);
        enemy = vector<int>(n, 0);
    };

    int findf(int i)
    {
        if (parents[i] != i)
            return parents[i] = findf(parents[i]);
        return parents[i];
    }

    void un_friend(int i, int j)
    {
        int ri = findf(i), rj = findf(j);
        if (ri != rj)
            parents[ri] = rj, cnt--;
    }
    void un_enemy(int i, int j)
    {
        if (enemy[i] == 0)
            enemy[i] = findf(j);
        else
            un_friend(enemy[i], j);
        if (enemy[j] == 0)
            enemy[j] = findf(i);
        else
            un_friend(enemy[j], i);
    }

    int count()
    {
        return cnt;
    }

    bool connected(int p, int q)
    {
        return findf(p) == findf(q);
    }
};

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    UF uf(n + 1);
    for (int i = 0; i < m; i++)
    {
        char op;
        int a, b;
        cin >> op >> a >> b;
        if (op == 'F')
            uf.un_friend(a, b);
        else
            uf.un_enemy(a, b);
    }
    cout << uf.count() - 1 << endl;
    return 0;
}